﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
    
    <Style x:Key="ExpanderDownHeaderStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Padding="{TemplateBinding Padding}" Background="{DynamicResource ExpanderBackground}"
                            CornerRadius="4">
                        <Grid Background="Transparent" SnapsToDevicePixels="False">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="19" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>
                            <Path x:Name="arrow" HorizontalAlignment="Center" VerticalAlignment="Center"
                                    Stroke="{DynamicResource ExpanderForeground}" StrokeThickness="2"
                                    SnapsToDevicePixels="false" Data="M 1,1.5 L 4.5,5 L 8,1.5" />
                            <ContentPresenter Grid.Column="1" Margin="4,0,0,0" HorizontalAlignment="Left"
                                    VerticalAlignment="Center" SnapsToDevicePixels="True" RecognizesAccessKey="True" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="true">
                            <Setter Property="Data" Value="M 1,4.5  L 4.5,1  L 8,4.5" TargetName="arrow" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter Property="Stroke" Value="{DynamicResource ExpanderForeground}" TargetName="arrow" />
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter Property="Stroke" Value="{DynamicResource ExpanderForeground}" TargetName="arrow" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="{x:Type Expander}" TargetType="{x:Type Expander}">
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="VerticalContentAlignment" Value="Stretch" />
        <Setter Property="BorderThickness" Value="4" />
        <Setter Property="Padding" Value="3" />
        <Setter Property="BorderBrush" Value="{DynamicResource ExpanderBackground}" />
        <Setter Property="Background" Value="{DynamicResource ExpanderBlackBackground}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Expander}">
                    <DockPanel>
                        <ToggleButton x:Name="HeaderSite" DockPanel.Dock="Top" Margin="1,0,1,1" MinWidth="0"
                                MinHeight="20" Style="{StaticResource ExpanderDownHeaderStyle}" Focusable="False"
                                IsChecked="{Binding Path=IsExpanded,Mode=TwoWay,RelativeSource={RelativeSource TemplatedParent}}"
                                Content="{TemplateBinding Header}" ContentTemplate="{TemplateBinding HeaderTemplate}"
                                ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                Foreground="{DynamicResource ExpanderForeground}"
                                FontFamily="{TemplateBinding FontFamily}" FontSize="{TemplateBinding FontSize}"
                                FontStyle="{TemplateBinding FontStyle}" FontStretch="{TemplateBinding FontStretch}"
                                FontWeight="{TemplateBinding FontWeight}"
                                HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />

                        <Border x:Name="ExpandSite" Visibility="Collapsed" DockPanel.Dock="Bottom"
                                CornerRadius="0,0,3,3" Margin="1,-4,1,0" BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                            <ContentPresenter Focusable="false"
                                    HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                    VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                    Margin="{TemplateBinding Padding}" />
                        </Border>
                    </DockPanel>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="true">
                            <Setter Property="Visibility" Value="Visible" TargetName="ExpandSite" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter Property="Foreground"
                                    Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
</ResourceDictionary>